This invention pertains to the field of computer interfaces, and more particularly to a method and an apparatus for resolving method overloading at runtime.
This application is related to the copending U.S. Application of Lance Kind entitled xe2x80x9cAPPARATUS AND METHOD FOR IMPLEMENTING A NETWORK PROTOCOL THAT SUPPORTS THE TRANSMISSION OF A VARIABLE NUMBER OF APPLICATION-USABLE OBJECTS OVER A NETWORK AS A SINGLE NETWORK TRANSMITTABLE CONTAINER OBJECT AND THE RE-CREATION OF THOSE APPLICATION-USABLE OBJECTS THEREFROMxe2x80x9d, Serial No. 09/335,933 filed on the same date as the present application, and hereby incorporates by reference all that is disclosed therein.
This invention originates from a need for an improved way to integrate third party components into an application. This situation can arise where an application is built into a framework, which, in object-oriented programming, is a reusable basic design structure that assists in building applications. The advantage of utilizing a framework in applications is that third party components (also known as software components), which are modular software routines that can be combined with other components to form an overall program, can be integrated into an application without the need for an application developer to understand the inner workings of the third party components.
Some third party components are written in programming languages that support method overloading. Method overloading is a process of reusing the same method name for a method that accepts different parameter types. This allows a programmer to reuse the full functionality of a method on different parameter data types without having to create unique method names for each data type. For example, a third party component can be a component for sorting an array. To support the various data types that the array can accommodate, the third party component might use the same method name on a variety of data types. For example, the following is a third party component which defines three methods all named Sort which can sort an array Arg for types integer, string, and float:
array Sort(array int Arg)
array Sort(array string Arg)
array Sort(array float Arg)
Method Sort is said to be overloaded because it is defined differently three times. An application that incorporates this third party component might only incorporate a Sort method for strings. When the Sort functionality is requested from the application via a graphical user interface (hereinafter xe2x80x9cGUIxe2x80x9d), by clicking on an icon, for example, an event is generated. An event is some action taken by a user which initiates some action initiated by a computer. Here, for example, the event would map to a pre-defined function to initiate a process to invoke an appropriate Sort method for strings. This process involves binding a method signature (i.e., the method name and its parameters) to a method implementation defined in the third party component. If a method signature must be bound to one of many method implementations, method overloading resolution takes place. For example, if method Sort is invoked by Sort(NameList), where NameList is defined as an array of string, the invoked method Sort must be resolved to a method defined in the third party component. That is, given three methods named Sort, each of which comprise different parameter data types, a computer process must determine which method Sort in EXAMPLE 1 to invoke. Furthermore, if method Sort is invoked by Sort(Num), where Num is defined as a long, method overloading resolution must also resolve the invoked method to the closest defined method, which requires knowledge of inheritance and data type conversion. Once method overloading is resolved, a method signature can be bound to a method implementation.
Since method overloading resolution is currently performed at compile-time, an application developer must write a program in a third party component""s native language to integrate component functionality so that methods can be resolved and bound. This task can be significantly onerous to an application""s development cycle if, at every cycle, developers had to write or modify programs for every functionality requested by a user. Assume, for example, that a custom word processing application incorporates a third party component for sorting strings into its application. If a user of the application subsequently decides that a sort method for integers would also be useful, an application developer would have to write a program to incorporate a sort function for integers into the application. At a minimum, this would require modifying one or more programs of the third party component and recompiling those programs. This requires an application developer to know the language of the third party component in addition to the language of the application, and also requires an application developer to have access to an appropriate compiler for the component""s language.
To alleviate or eliminate this footwork, a more dynamic approach to component integration is needed where programs do not need to be fully developed and then compiled to integrate new functionality. One solution is to bind methods at runtime rather than compile-time. Runtime method binding means that certain constructs of a third party component are pre-defined, which eliminates the need for an application developer to develop code in the component""s language. As a result, integrating new functionality merely requires some programming in the application""s language, rather than the component""s language. Since the application developer already knows the language of the application, it is a trivial task at most to write code in the application""s language to accommodate third party component functionality. For example, third party components which are developed with C++ virtual functions allow functions to be dynamically bound at runtime. If the application is written in language X, therefore, an application developer simply writes some code in language X to integrate a C++ virtual function. However, since type checking is performed at compile-time (with a C++ compiler), an application developer would still have to develop a program in the third party component""s language if there are overloaded methods requiring type-checking. Moreover, it is necessary to have access to header files and libraries of any classes whose API""s are used by the third party components, as well as a C++ compiler.
Java""s Core Reflection API (referred to as the Reflection API) also allows methods to be bound at runtime. However, because Reflection API does not perform method overloading resolution, the parameter list of the invoking call must be exactly the same as the parameter list of the method which is to be invoked. While Reflection API could be used in conjunction with a compiler, such as Java, to perform compile-time method overloading resolution, the use of a compiler would still mean that a program must be developed in a third party component""s language in order to integrate functionality from the component. Moreover, this would still require an application developer to know the specific language of the third party software component, and would also require the developer to have access to an appropriate compiler.
A need exists, therefore, for a method and an apparatus for integrating third party components that eliminates:
the need to know the specific language of a third party component; and
the need to have access to an appropriate compiler.
This invention solves this need by providing a runtime method overloading resolver that both resolves methods and binds them at runtime rather than compile-time. This invention is, in general, directed to method and apparatus for a runtime method overloading resolver.
Thus, the invention comprises an apparatus for resolving method overloading at runtime, comprising number of computer readable media and computer readable program code stored on the computer readable media for resolving a target method that comprises at least one parameter, where the program code comprises program code for accessing an application programming interface file comprising a number of methods belonging to the same class as the target method; and program code for selecting one of the methods, where the program code for selecting comprises program code for selecting an exact method, where a data type of each of the parameters of the exact method is the same data type of a corresponding parameter of the target method, and program code for determining that there if there is no exact method, then a best method is to be selected, where the best method is a method that most closely matches the target method.
The invention may also comprise an apparatus for resolving method overloading at runtime, comprising a number of computer readable media and computer readable program code stored on the computer readable media for resolving a target method that comprises at least one parameter, where the program code comprises program code for accessing an application programming interface file comprising a number of methods belonging to the same class as the target method; and program code for selecting one of the methods, where the program code for selecting comprises program code for selecting an exact method, where a data type of each of the parameters of the exact method is the same data type of a corresponding parameter of the target method, and program code for determining that if there is no exact method, then a best method is to be selected, where the best method is a method that most closely matches the target method, and the program code for selecting a best method comprises program code for selecting a number of candidate methods from the number of methods, where a data type of each of the parameters of the target method can be assigned to a data type of a corresponding parameter of each of the candidate methods; program code for scoring each of the candidate methods; and program code for selecting one of the candidate methods having the best score.
The invention may also comprise a method for resolving method overloading at runtime, comprising accessing an application programming interface file comprising a number of methods belonging to the same class as a target method; and selecting one of the methods which comprises selecting an exact method, where a data type of each of the parameters of the exact method is the same data type of a corresponding parameter of the target method, and determining that if there is no exact method, then a best method is to be selected, where a best method is a method that most closely matches the target method.
The invention may also comprise an apparatus for resolving method overloading at runtime, comprising means for accessing an application programming interface file comprising a number of methods belonging to the same class as a target method; and means for selecting one of said number of methods.